package com.ruoyi.question.controller;

import java.util.List;

import com.ruoyi.question.domain.QueQuestions;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.question.domain.QueListDetails;
import com.ruoyi.question.service.IQueListDetailsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 清单细则Controller
 * 
 * @author ruoyi
 * @date 2025-03-03
 */
@Controller
@RequestMapping("/detail/details")
public class QueListDetailsController extends BaseController
{
    private String prefix = "detail/details";

    @Autowired
    private IQueListDetailsService queListDetailsService;

    @RequiresPermissions("detail:details:view")
    @GetMapping()
    public String details()
    {
        return prefix + "/details";
    }

    /**
     * 查询清单细则列表
     */
    @RequiresPermissions("detail:details:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QueListDetails queListDetails)
    {
        startPage();
        List<QueQuestions> list = queListDetailsService.selectQueListDetailsList(queListDetails);
        return getDataTable(list);
    }

//    /**
//     * 导出清单细则列表
//     */
//    @RequiresPermissions("detail:details:export")
//    @Log(title = "清单细则", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(QueListDetails queListDetails)
//    {
//        List<QueListDetails> list = queListDetailsService.selectQueListDetailsList(queListDetails);
//        ExcelUtil<QueListDetails> util = new ExcelUtil<QueListDetails>(QueListDetails.class);
//        return util.exportExcel(list, "清单细则数据");
//    }

    /**
     * 新增清单细则
     */
    @RequiresPermissions("detail:details:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存清单细则
     */
    @RequiresPermissions("detail:details:add")
    @Log(title = "清单细则", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QueListDetails queListDetails)
    {
        return toAjax(queListDetailsService.insertQueListDetails(queListDetails));
    }

    /**
     * 修改清单细则
     */
    @RequiresPermissions("detail:details:edit")
    @GetMapping("/edit/{detailsId}")
    public String edit(@PathVariable("detailsId") String detailsId, ModelMap mmap)
    {
        QueListDetails queListDetails = queListDetailsService.selectQueListDetailsByDetailsId(detailsId);
        mmap.put("queListDetails", queListDetails);
        return prefix + "/edit";
    }

    /**
     * 修改保存清单细则
     */
    @RequiresPermissions("detail:details:edit")
    @Log(title = "清单细则", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QueListDetails queListDetails)
    {
        return toAjax(queListDetailsService.updateQueListDetails(queListDetails));
    }

    /**
     * 删除清单细则
     */
    @RequiresPermissions("detail:details:remove")
    @Log(title = "清单细则", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(queListDetailsService.deleteQueListDetailsByDetailsIds(ids));
    }
}
